package com.hongxing.baseaar.base

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.hongxing.baseaar.R
import java.lang.reflect.ParameterizedType

abstract class BaseMvpActivity<VB : ViewBinding, P : BasePresenter> : AppCompatActivity() {

    protected lateinit var binding: VB
    protected lateinit var presenter: P
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
        val superClass = javaClass.genericSuperclass
        if (superClass is ParameterizedType) {
            val clazz = superClass.actualTypeArguments[0] as Class<VB>
            val method = clazz.getDeclaredMethod("inflate", LayoutInflater::class.java)
            binding = method.invoke(null, layoutInflater) as VB
        }
        //EventBus.getDefault().register(this)
        presenter = getPresenterHolder()
        setContentView(binding.root)
        initView(savedInstanceState)
        overridePendingTransition(R.anim.slide_in_right, 0);
    }
    override fun finish() {
        super.finish()
        overridePendingTransition(0, R.anim.slide_out_left);
    }
    abstract fun getPresenterHolder(): P
    abstract fun initView(savedInstanceState: Bundle?)
    fun copyText(msg: String) {
        val clipboard: ClipboardManager =
            getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager

        // 创建 ClipData 对象
        val clip = ClipData.newPlainText("label", msg)
        // 设置剪切板内容
        clipboard.setPrimaryClip(clip);
    }


}